package com.hxgz.steel.controller;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.hxgz.steel.common.ServerResponse;
import com.hxgz.steel.util.ExcelUtil;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("meeting")
public class MeetingController {
  /*  @Autowired
    MeetIngService meetIngService;*/

    @RequestMapping(value = "save.do",method = RequestMethod.POST)
    public ServerResponse<String> save() {
        //Meeting meeting = new Meeting();
        //meeting.setName("第一次大家的会议");
        //return meetIngService.save(meeting);
        return null;
    }


    /**
     * 测试方法
     * @return
     */
    @RequestMapping(value = "testMethod.do",method = RequestMethod.POST)
    public ServerResponse<String> testMethod(HttpServletResponse response, MultipartFile multipartFile, HttpServletRequest request){
        //一、发送短信验证码
        //SendMsgUtil.sendIdentifyByDX("18696195739");

        //二、上传带有图片的excel,每个行数据有且只有一张图片，且图片位置在最后一列，图片添加顺序按时间顺序
        //必须打开ftp服务器，否则报错
       /* File file = new File("C:\\Users\\蒹葭苍苍\\Desktop\\testPic.xlsx");
        FileInputStream fileInputStream = null;
        try {
            fileInputStream = new FileInputStream(file);
            MultipartFile multipartFile = new MockMultipartFile(file.getName(), file.getPath(),
                    ContentType.APPLICATION_OCTET_STREAM.toString(), fileInputStream);
            ExcelUtil.uploadExcel(multipartFile);
        } catch (Exception e) {
            e.printStackTrace();
        }*/

       //三生成带有logo的二维码
        /*File logoFile = new File("D:\\file\\11.jpg");//二维码中间的logo图
        File QrCodeFile = new File("D:\\file\\11logo.jpg");//新生成的待logo的二维码图片
        String url = "https://www.baidu.com/";//二维码跳转地址
        String note = "访问百度连接";//二维码下方文字说明
        ZXingCode.drawLogoQRCode(logoFile, QrCodeFile, url, note);*/

        //四 excel导出
        //初始化数据
        List<String> list = new ArrayList();
        for(int i=0;i<5;i++){
            list.add("zhangsan");
            list.add("zhangsan2");
        }
        List<Map<String, String>> dataList = Lists.newArrayList();
        for (String str : list) {
            Map<String, String> dataMap = Maps.newHashMap();
            dataMap.put("名称",str);
            dataList.add(dataMap);
        }
        String excelName = "测试.xls";
        String[] columnName = {"名称"};
        ExcelUtil util = ExcelUtil.getInstance();
        Workbook workbook = util.dataToExcel(dataList, excelName, columnName);
        util.exportExcel(workbook,response,excelName);

        //五.微信公众号授权登陆   端口为80  入口为 wx/weixinLogin
        System.out.println(11111);
        //return ServerResponse.createBySuccess("testDemo.html");

        //上传图片
        //System.out.println(UploadPic.getPicAddress(multipartFile,request));
       return null;
    }


}
